import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


SERVER_API = 'http://119.29.129.235:10001'

from_site = 'smtp.163.com'
port = 465
from_email = '13432110777@163.com'
from_password = 'QCBHVCYQYOFYEELX'


class Action:
    def __init__(self, to_email: str):
        self.to_email = to_email
        msg = MIMEMultipart()
        msg['Subject'] = "赫巴兹智能办公系统提醒"
        msg['From'] = from_email
        self.msg = msg

    def send(self, content):
        self.msg.attach(MIMEText(content, 'html', 'utf-8'))
        handle = smtplib.SMTP_SSL(from_site, port)
        handle.login(from_email, from_password)
        handle.sendmail(
            from_email,
            [self.to_email],
            self.msg.as_string()
        )

    def phone_code(self, tid):
        content = f"""
            <p>请前往以下链接填写验证码:</p>\n
            <a href="{SERVER_API}/{tid}">点击此处跳转</a>\n
        """
        self.send(content)


if __name__ == '__main__':
    # Action('13680155288@139.com').phone_code('aaaa')
    Action('2054401068@qq.com').phone_code('aaaa')
